<template>
  <div class="main">
    <el-form ref="formRef" :inline="true" class="bg-bg_color w-[99/100] pl-8 pt-4">
      <el-form-item label="计划名称">
        <el-input placeholder="请输入计划名称" v-model="planName" clearable class="!w-[180px]" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" :icon="useRenderIcon(Search)" @click="onSearch">
          搜索
        </el-button>
      </el-form-item>
    </el-form>

    <PureTableBar title="权限列表" class="h100-60">
      <template #buttons>
        <p class="text-red-500 absolute left-[120px] leading-7 text-sm">注：双击查看详情</p>
        <el-button type="primary" :icon="useRenderIcon(Search)" class="invisible">
          添加
        </el-button>
      </template>
      <template v-slot="{ size, checkList }">
        <pure-table border align-whole="center" showOverflowTooltip table-layout="auto" :loading="loading" :size="size"
          :data="dataList" :columns="columns" :checkList="checkList" :pagination="pagination"
          @cell-dblclick="handleUpdate" :paginationSmall="size === 'small' ? true : false"
          :default-sort="{ prop: 'createTime', order: 'descending' }" :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)'
          }" @size-change="handleSizeChange" @current-change="handleCurrentChange">
          <template #operation="{ row }">
            <el-button class="reset-margin" link type="primary" :size="size" :icon="useRenderIcon(EditPen)"
              @click="handleUpdate(row)">
              修改
            </el-button>
            <el-button class="reset-margin" link type="danger" :size="size" :icon="useRenderIcon(Delete)"
              @click="handleDelete(row)">
              删除
            </el-button>
          </template>
        </pure-table>
      </template>
    </PureTableBar>

    <el-dialog @close="ClosePanelVisible(addDtoRef)" v-model="updatePanelVisible" :title="loadingTitle + '权限'" width="30%"
      center :close-on-click-modal="false">
      <el-form ref="addDtoRef" label-position="left" label-width="120px" :model="form">
        <el-form-item label="计划模板" prop="planTemplateId">
          <el-select v-model="form.planTemplateId" placeholder="请选择计划模板" class="!w-[220px]" value-key="planId"
            :disabled="isdisabled">
            <el-option v-for="item in isplanTemplateId" :key="item.planId" :label="item.planName" :value="item" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否可删除" prop="isDelete">
          <el-radio-group v-model="form.isDelete">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否可编辑" prop="isEdit">
          <el-radio-group v-model="form.isEdit">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否是公共模板" prop="isPublicTemplate">
          <el-radio-group v-model="form.isPublicTemplate">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="handSave(addDtoRef)">
            保存
          </el-button>
          <el-button @click="ClosePanelVisible(addDtoRef)">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Search from "@iconify-icons/ep/search";
import { useAuthority } from "./hooks";
const {
  form,
  dataList,
  loading,
  columns,
  planName,
  pagination,
  addDtoRef,
  isdisabled,
  loadingTitle,
  updatePanelVisible,
  isplanTemplateId,
  handSave,
  onSearch,
  handleUpdate,
  handleDelete,
  handleSizeChange,
  ClosePanelVisible,
  handleCurrentChange
} = useAuthority()
</script>

<style scoped lang="scss"></style>
